package com.mybatis.dao;
import com.mybatis.domain.Order;
import com.mybatis.domain.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 订单信息dao
 */
public interface IOrderDao {
    /**
     * 根据订单id查询订单及用户下的信息
     * @param id
     * @return
     */
    @Select("select * from t_order where id = #{orderId}")
    @Results(id = "orderResultMap", value = {
            @Result(property = "user", column = "userId", one = @One(select = "com.mybatis.dao.IUserDao.findUserById", fetchType = FetchType.LAZY))
    })
    Order findOrderById(int id);

    /**
     * 根据用户id查询用户下的所有订单
     * @param userId
     * @return
     */
    @Select("select * from t_order where userId = #{userId}")
    @ResultMap("orderResultMap")
    List<Order> findOrderByUserId(int userId);
}
